<template>
  <div class="profile">
    <!-- 顶部标题 -->
    <div class="header-title">
      <h2>诺威新型建材有限公司</h2>
    </div>
    
    <!-- 用户信息区域 -->
    <div class="user-info-section">
      <div class="user-card">
        <div class="user-avatar">
          <img :src="defaultAvatar" alt="用户头像" @error="handleImageError" />
        </div>
        <div class="user-details">
          <div class="user-id">
            <span class="label">微信昵称：</span>
            <span class="value">at4JKSPTkKrHgKyP7G9HMkFgU</span>
          </div>
          <div class="login-status">
            <span class="status-text">暂未登录</span>
          </div>
        </div>
      </div>
    </div>

    <!-- 功能菜单 -->
    <div class="menu-section">
      <div class="menu-item" @click="handleRegistrationInfo">
        <div class="menu-icon">
          <van-icon name="records" size="24" color="#4DD0E1" />
        </div>
        <div class="menu-text">
          <span>注册信息</span>
        </div>
        <van-icon name="arrow" size="16" color="#c8c9cc" />
      </div>
    </div>

    <!-- 退出登录按钮 -->
    <div class="logout-section">
      <div class="logout-button" @click="handleLogout">
        <span>退出登录</span>
      </div>
    </div>

    <!-- 底部导航 -->
    <van-tabbar v-model="active" class="custom-tabbar" @change="onTabChange">
      <van-tabbar-item icon="home-o">
        <span>首页</span>
      </van-tabbar-item>
      <van-tabbar-item icon="qr">
        <span>二维码</span>
      </van-tabbar-item>
      <van-tabbar-item icon="user-o">
        <span>我的</span>
      </van-tabbar-item>
    </van-tabbar>
  </div>
</template>

<script setup>
import { ref } from 'vue'
import { showToast, showConfirmDialog, showSuccessToast } from 'vant'
import { useRouter } from 'vue-router'

const active = ref(2) // 当前页面是我的页面
const router = useRouter()

// 默认头像SVG数据
const defaultAvatar = ref('')

// 底部导航切换
const onTabChange = (index) => {
  switch (index) {
    case 0:
      router.push('/')
      break
    case 1:
      router.push('/qr-code')
      break
    case 2:
      // 当前页面，不需要跳转
      break
  }
}

// 注册信息
const handleRegistrationInfo = () => {
  router.push('/registration-info')
}

// 退出登录
const handleLogout = async () => {
  try {
    await showConfirmDialog({
      title: '温馨提示',
      message: '您确定要退出当前账号吗？',
      confirmButtonText: '确认退出',
      cancelButtonText: '取消',
      confirmButtonColor: '#ff6b6b',
      cancelButtonColor: '#667eea',
      closeOnPopstate: true,
      lockScroll: true,
      className: 'custom-logout-dialog',
      messageAlign: 'center'
    })
    
    // 这里可以添加实际的退出登录逻辑
    // 清除用户信息
    // localStorage.removeItem('userToken')
    // sessionStorage.clear()
    
    showToast({
      message: '退出成功，感谢您的使用',
      type: 'success',
      duration: 2000,
      className: 'custom-success-toast'
    })
    
    // 延迟跳转，让用户看到成功提示
    setTimeout(() => {
      // 可以跳转到登录页面或首页
      router.push('/')
    }, 1000)
    
  } catch (error) {
    // 用户点击了取消或按了返回键
    console.log('用户取消了退出操作')
  }
}

// 头像加载失败处理
const handleImageError = (event) => {
  // 使用默认头像
  event.target.src = defaultAvatar.value
}
</script>

<style scoped>
/* 全局样式优化 - 禁止滚动，强制一页显示 */
.profile {
  background: linear-gradient(180deg, #f8faff 0%, #f0f4ff 100%);
  height: 100vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* 顶部标题美化 - 精简尺寸 */
.header-title {
  text-align: center;
  padding: 20px 0 16px 0;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  position: relative;
  overflow: hidden;
  flex-shrink: 0;
}

.header-title::before {
  content: '';
  position: absolute;
  top: -50%;
  left: -50%;
  width: 200%;
  height: 200%;
  background: radial-gradient(circle, rgba(255,255,255,0.1) 0%, transparent 70%);
  animation: shimmer 3s ease-in-out infinite;
}

@keyframes shimmer {
  0%, 100% { transform: translate(-50%, -50%) rotate(0deg); }
  50% { transform: translate(-50%, -50%) rotate(180deg); }
}

.header-title h2 {
  font-size: 20px;
  font-weight: 600;
  color: white;
  margin: 0;
  text-shadow: 0 2px 4px rgba(0,0,0,0.2);
  letter-spacing: 1px;
  position: relative;
  z-index: 1;
}

/* 用户信息区域 */
.user-info-section {
  padding: 20px 16px;
  flex-shrink: 0;
}

.user-card {
  background: white;
  border-radius: 16px;
  padding: 20px;
  display: flex;
  align-items: center;
  gap: 16px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
  border: 1px solid rgba(102, 126, 234, 0.1);
  position: relative;
  overflow: hidden;
}

.user-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: linear-gradient(135deg, rgba(102, 126, 234, 0.02), rgba(118, 75, 162, 0.02));
  pointer-events: none;
}

.user-avatar {
  width: 60px;
  height: 60px;
  border-radius: 12px;
  overflow: hidden;
  background: #f5f5f5;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  z-index: 1;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.user-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.user-details {
  flex: 1;
  position: relative;
  z-index: 1;
}

.user-id {
  display: flex;
  align-items: center;
  margin-bottom: 8px;
  flex-wrap: wrap;
  gap: 4px;
}

.user-id .label {
  font-size: 14px;
  color: #8f9bb3;
  font-weight: 500;
}

.user-id .value {
  font-size: 13px;
  color: #2c3e50;
  font-weight: 400;
  letter-spacing: 0.5px;
  word-break: break-all;
}

.login-status {
  display: flex;
  align-items: center;
}

.status-text {
  font-size: 14px;
  color: #ff8800;
  font-weight: 500;
}

/* 功能菜单 */
.menu-section {
  padding: 0 16px;
  flex-shrink: 0;
}

.menu-item {
  background: white;
  border-radius: 12px;
  padding: 18px 20px;
  display: flex;
  align-items: center;
  gap: 16px;
  cursor: pointer;
  transition: all 0.3s ease;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
  border: 1px solid rgba(102, 126, 234, 0.1);
  position: relative;
  overflow: hidden;
}

.menu-item::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: linear-gradient(135deg, rgba(77, 208, 225, 0.05), rgba(38, 198, 218, 0.05));
  opacity: 0;
  transition: opacity 0.3s ease;
}

.menu-item:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.12);
  border-color: rgba(102, 126, 234, 0.2);
}

.menu-item:hover::before {
  opacity: 1;
}

.menu-item:active {
  transform: translateY(0) scale(0.98);
}

.menu-icon {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  background: linear-gradient(135deg, rgba(77, 208, 225, 0.1), rgba(38, 198, 218, 0.15));
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  z-index: 1;
  box-shadow: 0 2px 8px rgba(77, 208, 225, 0.2);
}

.menu-text {
  flex: 1;
  position: relative;
  z-index: 1;
}

.menu-text span {
  font-size: 16px;
  color: #2c3e50;
  font-weight: 600;
  letter-spacing: 0.5px;
}

/* 退出登录按钮 */
.logout-section {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px 16px 20px 16px;
}

.logout-button {
  background: linear-gradient(135deg, #ff6b6b, #ff5252);
  color: white;
  border-radius: 12px;
  padding: 16px 40px;
  cursor: pointer;
  transition: all 0.3s ease;
  box-shadow: 0 6px 20px rgba(255, 107, 107, 0.3);
  position: relative;
  overflow: hidden;
  border: none;
  outline: none;
  min-width: 120px;
  text-align: center;
}

.logout-button::before {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.2), transparent);
  transition: left 0.5s;
}

.logout-button:hover::before {
  left: 100%;
}

.logout-button:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 32px rgba(255, 107, 107, 0.4);
}

.logout-button:active {
  transform: translateY(0) scale(0.98);
  box-shadow: 0 4px 16px rgba(255, 107, 107, 0.3);
}

.logout-button span {
  font-size: 16px;
  font-weight: 600;
  position: relative;
  z-index: 1;
  letter-spacing: 0.5px;
}

/* 底部导航美化 */
.custom-tabbar {
  background: white;
  border-top: 1px solid rgba(102, 126, 234, 0.1);
  box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.06);
  backdrop-filter: blur(10px);
  padding: 2px 0;
  min-height: 48px;
  flex-shrink: 0;
}

.custom-tabbar .van-tabbar-item {
  color: #8f9bb3;
  transition: all 0.3s ease;
}

.custom-tabbar .van-tabbar-item--active {
  color: #667eea;
  font-weight: 600;
}

.custom-tabbar .van-tabbar-item--active .van-icon {
  transform: scale(1.1);
}

/* 响应式优化 */
@media screen and (max-width: 375px) {
  .header-title h2 {
    font-size: 18px;
  }
  
  .user-card {
    padding: 16px;
    gap: 12px;
  }
  
  .user-avatar {
    width: 50px;
    height: 50px;
  }
  
  .user-id .value {
    font-size: 12px;
  }
  
  .menu-item {
    padding: 16px 18px;
    gap: 14px;
  }
  
  .menu-icon {
    width: 40px;
    height: 40px;
  }
  
  .logout-button {
    padding: 14px 36px;
  }
}

@media screen and (max-height: 667px) {
  .user-info-section {
    padding: 16px;
  }
  
  .logout-section {
    padding: 24px 16px 16px 16px;
  }
}

/* 加载动画 */
@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(30px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes slideInLeft {
  from {
    opacity: 0;
    transform: translateX(-20px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

.user-card {
  animation: slideInLeft 0.6s ease forwards;
}

.menu-item {
  animation: fadeInUp 0.6s ease 0.2s forwards;
}

.logout-button {
  animation: fadeInUp 0.6s ease 0.4s forwards;
}

/* 自定义退出登录对话框样式 */
:deep(.custom-logout-dialog) {
  border-radius: 16px;
  overflow: hidden;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);
}

:deep(.custom-logout-dialog .van-dialog__header) {
  padding: 24px 24px 16px 24px;
  background: linear-gradient(135deg, #f8f9ff 0%, #e8f4f8 100%);
  border-bottom: 1px solid rgba(102, 126, 234, 0.1);
}

:deep(.custom-logout-dialog .van-dialog__title) {
  font-size: 18px;
  font-weight: 600;
  color: #2c3e50;
  text-align: center;
}

:deep(.custom-logout-dialog .van-dialog__content) {
  padding: 20px 24px;
  background: white;
}

:deep(.custom-logout-dialog .van-dialog__message) {
  font-size: 16px;
  color: #2c3e50;
  line-height: 1.5;
  text-align: center;
}

:deep(.custom-logout-dialog .van-dialog__footer) {
  padding: 16px 24px 24px 24px;
  background: white;
  border-top: 1px solid rgba(102, 126, 234, 0.08);
  display: flex;
  gap: 12px;
}

:deep(.custom-logout-dialog .van-button) {
  flex: 1;
  height: 44px;
  border-radius: 10px;
  font-size: 15px;
  font-weight: 600;
  border: none;
  transition: all 0.3s ease;
}

:deep(.custom-logout-dialog .van-button--cancel) {
  background: linear-gradient(135deg, #667eea, #764ba2);
  color: white;
  box-shadow: 0 2px 8px rgba(102, 126, 234, 0.3);
}

:deep(.custom-logout-dialog .van-button--confirm) {
  background: linear-gradient(135deg, #ff6b6b, #ff5252);
  color: white;
  box-shadow: 0 2px 8px rgba(255, 107, 107, 0.3);
}

:deep(.custom-logout-dialog .van-button:active) {
  transform: scale(0.98);
}

/* 自定义成功提示样式 */
:deep(.custom-success-toast) {
  background: linear-gradient(135deg, #4caf50, #45a049);
  color: white;
  border-radius: 12px;
  box-shadow: 0 4px 16px rgba(76, 175, 80, 0.3);
  font-weight: 500;
}
</style>